package com.crl.module.connecter.decoder
{
	import com.crl.core.IDispose;
	import com.crl.module.connecter.core.INetSender;
	import com.crl.module.connecter.handler.INetHandler;
	import com.crl.module.connecter.model.CommandInfo;
	
	import flash.utils.getQualifiedClassName;
	
	
	/**
	 * 抽像解析器,解析一条语句;
	 * @author crl
	 * 
	 */	
	public class AbstractDecoder implements IDecoder, IDispose
	{
		protected var parsersManager:INetHandler;
		protected var type:String;
		protected var commandInfo:CommandInfo;
        protected var server:INetSender;
        
        
		public function AbstractDecoder(type:String="abstractParser")
		{
		}
		public function set manager(handler:INetHandler):void{
			parsersManager=handler;
		}
		
		
		public function onData(comandInfo:CommandInfo, server:INetSender):void
		{
			this.commandInfo=commandInfo;
            this.server=server;
            
		}
		
		public function decode():void{
			var data:Object=this.commandInfo.data;
			
			if(validate(data)==false){
				throw new Error("数据没有验证通过");
			}
			
			
			this.parse(parse);
		}
		
		protected function parse(data:Object):*{
			return data;
		}
		
		/**
         * 验证信息的可靠性;
         * @return
         *
         */		
        protected function validate(data:Object):Boolean{
            return true;
        }
		
		
		public function getType():String
		{
			return this.type;
		}
		
		public function toString():String{
            return getQualifiedClassName(this);
        }
		
		public function clear():void{
			
		}
		
		public function dispose():void{
			
		}
	}
}